package com.xuyh.mqtt.rest;


import com.xuyh.mqtt.realtime.dal.DeviceDataDal;
import com.xuyh.mqtt.realtime.dto.DeviceDataDto;
import com.xuyh.mqtt.realtime.dto.DeviceDataParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/MongodbTest")
public class MongodbController {

    @Autowired
    private DeviceDataDal deviceDataDal;

    @GetMapping("/getAllDeviceData")
    public List<DeviceDataDto> getAllDeviceData() {
        return deviceDataDal.findAll();
    }

    @PostMapping("/addNewDeviceData")
    public DeviceDataDto addNewDeviceData(@RequestBody DeviceDataDto deviceDataDto) {
        return deviceDataDal.save(deviceDataDto);
    }

    @GetMapping("/findByCondition")
    public List<DeviceDataDto> findByCondition(@RequestBody DeviceDataParam deviceDataParam) {
        return deviceDataDal.findByCondition(deviceDataParam.getAddr(), deviceDataParam.getBeginTime(), deviceDataParam.getEndTime());
    }

}
